// 商品管理（支持超管+商家角色）
import request from '../utils/request'
 
const list = async () => {
  try {
    const res = await request.get('/api/mall/product/list')
    console.log('请求成功', res.data)
    return res.data
  } catch (error) {
    console.error('请求失败', error)
    return null
  }
}

// 新增商品
const addProduct = async (payload) => {
  try {
    const res = await request.post('/api/mall/product/add', payload)
    return res.data
  } catch (error) {
    console.error('添加商品失败', error)
    return null
  }
}

// 编辑商品
const editProduct = async (payload) => {
  try {
    const res = await request.put('/api/mall/product/edit', payload)
    return res.data
  } catch (error) {
    console.error('编辑商品失败', error)
    return null
  }
}

// 删除商品
const deleteProduct = async (productId) => {
  try {
    const res = await request.delete(`/api/mall/product/delete/${productId}`)
    return res.data
  } catch (error) {
    console.error('删除商品失败', error)
    return null
  }
}

export { list, addProduct, editProduct, deleteProduct }